<?php

namespace Biblibase\SiteBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use Biblibase\SiteBundle\Form\AuteurType;
use Biblibase\SiteBundle\Form\EditeurType;
use Biblibase\SiteBundle\Form\CollectionType;
use Biblibase\SiteBundle\Form\ImageType;

class UpdateLivreType extends AbstractType
{
        /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('titre', 'text')
            ->add('auteur', 'collection', array('type' => new AuteurType(),
            												'allow_add'=> true,
            												'allow_delete' => true))
            ->add('collection', new CollectionType())
            ->add('editeur', new EditeurType())
            ->add('themes', 'entity', array(
            		'label' => 'Thèmes',
  						'class'    => 'BiblibaseSiteBundle:Theme',
  						'property' => 'nom',
  						'multiple' => true,
  						'expanded' => true,
  						'label_attr' => array('class', 'labelTitre')))
            ->add('classement','entity', array(
  						'class'    => 'BiblibaseSiteBundle:Classement',
 					 	'property' => 'nom',
  						'multiple' => false,
  						'required' => false,
  						'label_attr' => array('id', 'labelTitre')))
            ->add('num', 'text', array('label' => 'N°', 'required' => false))
            ->add('isbn', 'text', array('label' => 'Isbn'))
            ->add('annee', 'text', array('label' => 'Année de parution', 'required' => false))
            ->add('description', 'textarea', array('label' => 'Description', 'required' => false))
            ->add('image', new ImageType(), array('label' => "Modifier l'image", 'required' => false))
            
        ;
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Biblibase\SiteBundle\Entity\Livre'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'biblibase_sitebundle_updatelivre';
    }
}
